package cn.ncu.wechat.controller;

import cn.ncu.wechat.model.LoginRequest;
import cn.ncu.wechat.service.UserService;
import cn.ncu.wechat.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;


@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService userService;

//    @PostMapping("/test")
//    public Result<?> test(){
//        return Result.success();
//    }

    @PostMapping ("/wx/login")
    public Result<?> Login(@RequestBody LoginRequest loginRequest){
        //System.out.println(loginRequest.toString());
        return userService.login(loginRequest.getUserInfo(),loginRequest.getCode());
    }

    @GetMapping("wx/user/info")
    public Result<?> GetUserInfo(@RequestHeader("Authorization") Optional<String> authorizationHeader){
        return userService.getUserInfo(authorizationHeader.get());
    }
}

